package demo;

import javax.swing.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created By  醉美柳舞之众星捧月
 *
 * @author song
 * @date 2021/4/19 14:49
 */
public class Main extends JFrame {

    public Main(JFrame e) {
        super("天呈智能导出加班详情 小工具 @ songxiankun2008@126.com");
        mainPanel();
        setSize(380, 420);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setIconImage(new ImageIcon("src/main/resources/pig.png").getImage());
        setVisible(true);
        setLocationRelativeTo(null);
        repaint(1000);
        validate();
    }

    public static JTextField outPutMonth;
    public static JTextField restInWeekList;
    public static JTextField currentWorkDays;
    public static JTextField workInWeekEndList;

    public void mainPanel() {

        getContentPane().setLayout(null);

        JLabel intPutMonthLabel = new JLabel("请输入当前导出月份 (1~12)");
        intPutMonthLabel.setBounds(30, 20, 350, 30);
        intPutMonthLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        getContentPane().add(intPutMonthLabel);

        outPutMonth = new JTextField(1);
        outPutMonth.setBounds(30, 50, 250, 30);
        outPutMonth.setFont(new Font("华文行楷", Font.PLAIN, 18));
        getContentPane().add(outPutMonth);

        JLabel intPutWorkDaysLabel = new JLabel("请输入当前月的标准出勤天数 (1~31)");
        intPutWorkDaysLabel.setBounds(30, 85, 350, 30);
        intPutWorkDaysLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        getContentPane().add(intPutWorkDaysLabel);

        currentWorkDays = new JTextField(1);
        currentWorkDays.setBounds(30, 115, 250, 30);
        currentWorkDays.setFont(new Font("华文行楷", Font.PLAIN, 18));
        getContentPane().add(currentWorkDays);

        JLabel currentWorkDaysLabel = new JLabel("当前月在周末上班有哪些天[逗号分割] (1~31)");
        currentWorkDaysLabel.setBounds(30, 140, 350, 30);
        currentWorkDaysLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        getContentPane().add(currentWorkDaysLabel);

        workInWeekEndList = new JTextField(1);
        workInWeekEndList.setBounds(30, 170, 250, 30);
        workInWeekEndList.setFont(new Font("华文行楷", Font.PLAIN, 18));
        getContentPane().add(workInWeekEndList);

        JLabel workInWeekEndListLabel = new JLabel("当前月在周一到周五休息的天数[逗号分割] (1~31)");
        workInWeekEndListLabel.setBounds(30, 195, 350, 30);
        workInWeekEndListLabel.setFont(new Font("微软雅黑", Font.PLAIN, 15));
        getContentPane().add(workInWeekEndListLabel);

        restInWeekList = new JTextField(1);
        restInWeekList.setBounds(30, 225, 250, 30);
        restInWeekList.setFont(new Font("华文行楷", Font.PLAIN, 18));
        getContentPane().add(restInWeekList);


        JButton outPutCurrentMonthExcel = new JButton("导出当前月份的Excel详情");
        outPutCurrentMonthExcel.setBounds(30, 260, 250, 30);
        outPutCurrentMonthExcel.addMouseListener(new MouseClickOutPutCurrentMonthEnter());
        outPutCurrentMonthExcel.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    MouseClickOutPutCurrentMonthEnter mouseClickoutPutCurrentMonthEnter = new MouseClickOutPutCurrentMonthEnter();
                    mouseClickoutPutCurrentMonthEnter.mouseClicked(null);
                }
            }
        });
        getContentPane().add(outPutCurrentMonthExcel);

        JButton outPutCurrentYearExcel = new JButton("导出当前年的Excel详情");
        outPutCurrentYearExcel.setBounds(30, 300, 250, 30);
        outPutCurrentYearExcel.addMouseListener(new MouseClickOutPutCurrentYearEnter());
        outPutCurrentYearExcel.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                    MouseClickOutPutCurrentYearEnter mouseClickOutPutCurrentYearEnter = new MouseClickOutPutCurrentYearEnter();
                    mouseClickOutPutCurrentYearEnter.mouseClicked(null);
                }
            }
        });
        getContentPane().add(outPutCurrentYearExcel);

        JButton selectFile = new JButton("选择审批文件 - 导出审批数据");
        selectFile.setBounds(30, 340, 250, 30);
        selectFile.setPreferredSize(new Dimension(100, 40));
        selectFile.addMouseListener(new MouseClickSelectFileEnter());
        getContentPane().add(selectFile);

    }

    private static void playMusic() {
        try {
            URL cb;
            File f = new File("src/main/resources/sound.wav");
            cb = f.toURL();
            AudioClip aau;
            aau = Applet.newAudioClip(cb);
            aau.play();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        playMusic();
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (Throwable e) {
            e.printStackTrace();
        }
        EventQueue.invokeLater(() -> {
            try {
                Main frame = new Main(null);
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    }
}
